package com.dhl.rabbitmq.six;

import com.dhl.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.slf4j.Logger;

import java.nio.charset.StandardCharsets;

/**
 * @author danghailiang
 */
public class ReceiveLogsDirect01 {

    public static final String EXCHANGE_NAME= "direct_log";

    public static void main(String[] args) throws Exception {
        // 获取信道
        Channel channel = RabbitUtils.getChannel();
        // 声明交换
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        // 声明队列
        String queueName = "disk";
        channel.queueDeclare(queueName,false,false,false,null);
        // 队列绑定交换
        channel.queueBind(queueName,EXCHANGE_NAME,"error");
        // 成功回调处理
        DeliverCallback deliverCallback = (sepTag, message) ->{
            System.out.println(new String(message.getBody(), StandardCharsets.UTF_8));
        };
        // 失败回调处理
        CancelCallback cancelCallback = (sepTag) ->{};
        // 接收消息
        channel.basicConsume(queueName,false,deliverCallback,cancelCallback);
    }
}
